<template>
	<view>
		<image class="missback" src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/indexback.png" mode="widthFix"></image>
		<headers title="我的喜糖" showback="true" navBackcolor="transparent"></headers>
		<view class="candy-mine">
			<view class="candy-mine-banner">
				<image class="candy-mine-banner-bg" src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/mission/bg3.png"
					style="height: 322rpx;width: 686rpx;" mode="">
				</image>
				<view class="candy-mine-banner-header u-flex u-row-between">
					<view class="candy-mine-banner-header-left u-flex">
						<view class="" style="margin-right:8rpx">
							全部喜糖
						</view>
						<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/mission/warm.png" style="width: 32rpx;height: 32rpx;" mode="">
						</image>
					</view>
					<view class="candy-mine-banner-header-right u-flex"
						@click="$Router.push('/pages/index/mission/candy-loss')">
						<view class="" style="margin-right:8rpx">
							喜糖明细
						</view>
						<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/mission/chevron-right.png" style="width: 32rpx;height: 32rpx;"
							mode=""></image>
					</view>
				</view>
				<view class="candy-mine-banner-main">
					<view class="candy-mine-banner-main-num">
						{{ info.score }}
					</view>
					<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/mission/gold-row.png" style="height: 2rpx;display: block;"
						mode=""></image>
					<view class="candy-mine-banner-main-flex u-flex">
						<view class="candy-mine-banner-main-flex-item">
							<view class="candy-mine-banner-main-flex-item-title" style="color: #FCFDFFFF;">
								免费获得
							</view>
							<view class="candy-mine-banner-main-flex-item-value" style="font-size: 24rpx;color: #FCFDFFFF;">
								{{ info.base_score }}
							</view>
						</view>
						<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/mission/gold-col.png" style="width: 2rpx;height: 60rpx;"
							mode=""></image>
						<view class="candy-mine-banner-main-flex-item">
							<view class="candy-mine-banner-main-flex-item-title" style="color: #FCFDFFFF;">
								付费充值
							</view>
							<view class="candy-mine-banner-main-flex-item-value" style="font-size: 24rpx;color: #FCFDFFFF;">
								0
							</view>
						</view>
						<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/mission/gold-col.png" style="width: 2rpx;height: 60rpx;"
							mode=""></image>
						<view class="candy-mine-banner-main-flex-item">
							<view class="candy-mine-banner-main-flex-item-title" style="color: #FCFDFFFF;">
								任务奖励
							</view>
							<view class="candy-mine-banner-main-flex-item-value" style="font-size: 24rpx;color: #FCFDFFFF;">
								0
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="candy-mine-get">
				<view class="candy-mine-get-title">
					充值喜糖
				</view>
				<view class="candy-mine-get-main u-flex">
					<view class="candy-mine-get-main-item act" @click="choosePrice(item)"
						v-for="(item, index) in priceList" :key="index">
						<view class="candy-mine-get-main-item-bg" v-if="choosePriceId == item.id">
							<image class="candy-mine-get-main-item-bg-select"
								src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/mission/select.png" mode=""></image>
						</view>
						<view class="candy-mine-get-main-item-sale" v-if="item.is_first == 1">
							限首次购买
						</view>
						<view class="candy-mine-get-main-item-sale" v-if="item.discount != 0">
							限时{{ item.discount }}折
						</view>
						<view class="candy-mine-get-main-item-top u-flex u-row-center">
							<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/index/candy.png" mode=""></image>
							<view class="">
								{{ item.number }}
							</view>
						</view>
						<view class="candy-mine-get-main-item-down">
							￥{{ item.price }}
						</view>
					</view>
				</view>
				<view class="candy-mine-get-warm">
					<view class="">
						获取喜糖遇到困难？联系客服
					</view>
					<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/arrow-right.png" mode=""></image>
				</view>
			</view>
			<view class="candy-mine-btn" @click="buySugar()">
				<image src="https://zaiyiqi-1322608024.cos.ap-nanjing.myqcloud.com/static/img/btn/288x44.png" mode=""></image>
				<view class="candy-mine-btn-con">
					立即充值
				</view>
			</view>
		</view>
	</view>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
import headers from '@/components/headers/index.vue'
export default {
	// 组件名称
	name: 'demo',
	// 组件参数 接收来自父组件的数据
	props: {},
	// 局部注册的组件,import引入的组件需要注入到对象中才能使用
	components: {
		headers,
	},
	// 组件状态值
	data() {
		return {
			choosePriceId: 0,
			priceList: [],
			info: {}
		}
	},
	// 计算属性
	computed: {},
	// 侦听器
	watch: {},
	// 组件方法
	methods: {
		getInfo(){
			this.$http('user.info').then(res=>{
				console.log(res)
				this.info = res.data
				// this.$utils.setCache('userinfo',JSON.stringify(res.data))
			})
		},
		// 选择喜糖
		choosePrice(item) {
			this.choosePriceId = item.id
		},
		// 获取喜糖列表
		getSugar() {
			this.$http('config.sugar').then(res => {
				console.log(res)
				this.priceList = res.data
			})
		},
		// 购买喜糖
		buySugar(){
			this.$http('config.buySugar',{
				token: uni.getStorageSync('token'),
				id: this.choosePriceId
			}).then(res=>{
				console.log(res)
			})
		}
	},
	// 以下是生命周期钩子   注：没用到的钩子请自行删除
	/**
	 * 在实例初始化之后，组件属性计算之前，如data属性等
	 */
	beforeCreate() { },
	/**
	 * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
	 */
	created() { 
		this.getSugar()
		this.getInfo()
	},
	/**
	 * 在挂载开始之前被调用：相关的 render 函数首次被调用。
	 */
	beforeMount() { },
	/**
	 * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
	 * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
	 */
	mounted() { },
	/**
	 * 数据更新时调用，发生在虚拟 DOM 重新渲染和打补丁之前。
	 * 你可以在这个钩子中进一步地更改状态，这不会触发附加的重渲染过程。
	 */
	beforeUpdate() { },
	/**
	 * 由于数据更改导致的虚拟 DOM 重新渲染和打补丁，在这之后会调用该钩子。
	 * 当这个钩子被调用时，组件 DOM 已经更新，所以你现在可以执行依赖于 DOM 的操作。
	 */
	updated() { },
	/**
	 * keep-alive 组件激活时调用。 仅针对keep-alive 组件有效
	 */
	activated() { },
	/**
	 * keep-alive 组件停用时调用。 仅针对keep-alive 组件有效
	 */
	deactivated() { },
	/**
	 * 实例销毁之前调用。在这一步，实例仍然完全可用。
	 */
	beforeDestroy() { },
	/**
	 * Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，
	 * 所有的事件监听器会被移除，所有的子实例也会被销毁。
	 */
	destroyed() { }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<style scoped lang="scss">
.candy-mine {
	width: 100%;
	height: 100%;
	// background: linear-gradient(#F1EFFFFF 0%, #FFFFFF 40%, #F7F8FA 100%);
	// padding-top: $nav-top-height;
	position: relative;
	z-index: 9;

	&-banner {
		width: 686rpx;
		height: 322rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		position: relative;
		padding: 32rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		color: #FCFDFFFF;
		margin: 32rpx;

		&-bg {
			position: absolute;
			top: 0;
			left: 0;
		}

		&-header {
			position: absolute;
			width: calc(100% - 64rpx);

			&-left {
				font-size: 28rpx;
				font-weight: 400;
				color: #FCFDFF;
			}

			&-right {
				font-size: 24rpx;
				font-weight: 400;
				color: #FCFDFF;
			}
		}

		&-main {

			position: absolute;
			width: calc(100% - 64rpx);
			top: 92rpx;

			&-num {
				font-size: 48rpx;
				font-family: DINPro-Bold, DINPro;
				font-weight: 400;
				color: #FCFDFF;
				margin-bottom: 24rpx;
			}

			&-flex {
				margin-top: 32rpx;
				justify-content: center;

				&-item {
					text-align: center;
					width: 33%;
					font-size: 24rpx;
					font-weight: 400;

					&-title {
						color: #E7E7F1;
						margin-bottom: 6rpx;
					}

					&-value {
						color: #FCFDFF;
					}
				}
			}
		}
	}

	&-get {
		margin: 60rpx 32rpx 48rpx;

		&-title {
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 400;
			color: #2E3033;
		}

		&-main {
			flex-flow: wrap;

			&-item {
				position: relative;
				margin-top: 48rpx;
				margin-right: 12rpx;
				width: 216rpx;
				height: 152rpx;
				background: #F8F9FE;
				border-radius: 16rpx;
				display: flex;
				align-items: center;
				flex-direction: column;
				justify-content: center;

				&-bg {
					position: absolute;
					width: 216rpx;
					height: 152rpx;
					left: 0;
					top: 0;
					border-radius: 16rpx;
					border: 4rpx solid #A4A0FE;

					&-select {
						width: 39.67rpx;
						height: 40.5rpx;
						position: absolute;
						right: -2rpx;
						bottom: -2rpx;
					}

				}


				&-sale {
					background: #FF7339;
					border-radius: 16rpx 0rpx 20rpx 0rpx;
					font-size: 20rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					padding: 2rpx 20rpx;
					position: absolute;
					top: -16rpx;
					left: 0;
					display: inline-block;
				}

				&-top {
					font-size: 28rpx;
					font-family: DINPro-Medium, DINPro;
					font-weight: 400;
					color: #4D4135;

					image {
						height: 40rpx;
						width: 40rpx;
					}
				}

				&-down {
					margin-top: 12rpx;
					text-align: center;
					font-size: 28rpx;
					font-weight: 400;
					color: #FF7339;
				}
			}
		}

		&-warm {
			margin: 60rpx 0;
			text-align: center;
			justify-content: center;
			display: flex;
			font-size: 24rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: normal;
			color: #8A9199;

			image {
				width: 32rpx;
				height: 32rpx;
			}
		}
	}

	&-btn {
		margin: 0 auto;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 576rpx;
		height: 88rpx;
		position: relative;

		image {
			width: 576rpx;
			height: 88rpx;
			position: absolute;
			top: 0;
			left: 0;
		}

		&-con {
			width: 100%;
			height: 100%;
			text-align: center;
			line-height: 88rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #FCFDFF;
			position: relative;
		}
	}
}
</style>
